<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>导入预览</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#myFile").change(function () {
		        var filepath = $("input[name='file']").val();
		        var extStart = filepath.lastIndexOf(".");
		        var ext = filepath.substring(extStart, filepath.length).toUpperCase();
		        if (ext != ".xls" && ext != ".XLS" && ext != ".XLSX" && ext != ".xlsx") {
		          alertx("文件限于xls和xlsx格式");
		          $("#fileSize").text("");
		          $("#myFile").val("");
		          return false;
		        }
		        var file_size = 0;
		        if ($.browser.msie) {
		          var img = new Image();
		          img.src = filepath;
		          while (true) {
		            if (img.fileSize > 0) {
		              if (img.fileSize > 3 * 1024 * 1024) {
		                alertx("文件不大于100MB。");
		                $("#myFile").val("");
		              } else {
		                var num03 = img.fileSize / 1024;
		                num04 = num03.toFixed(2)
		                $("#fileSize").text(num04 + "KB");
		              }
		              break;
		            }
		          }
		        } else {
		          file_size = this.files[0].size;
		          var size = file_size / 1024;
		          if (size > 1024*20) {
		            alert("上传的文件大小不能超过20M！");
		            $("#myFile").val("");
		          } else {
		            var num01 = file_size / 1024;
		            num02 = num01.toFixed(2);
		            $("#fileSize").text(num02 + " KB");
		          }
		        }
		        return true;
		      });
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		function groupForm(groupId,projectId){
			var url = "${ctx}/pro/taskGroup/form?project.id="+projectId+"&id="+groupId;
			top.$.jBox.open("iframe:"+url, "任务组详情",810,$(top.document).height()-120,{
                buttons:{"提交":"ok", "关闭":true}, bottomText:"任务组详情",submit:function(v, h, f){
                    var code;
                    if (v=="ok"){
                    	// 执行保存
                        //loading('正在提交，请稍等...');
                    	var flag = h.find("iframe")[0].contentWindow.submitForm();
                    	if(flag){
                    		location.reload();
                    	}
                        return false;
                    }
                }, loaded:function(h){
                    $(".jbox-content", top.document).css("overflow-y","hidden");
                }
            });
		}
		function importExcel(){
			var projectId = $("#projectId").val();
			var key = $("#key").val();
			var url = "${ctx}/pro/taskGroup/importExcel?projectId="+projectId+"&key="+key;
			if(key != null && key != ""){
				loading("导入中，请稍等...");
				$.ajax({
					  type: 'POST',
					  url: url,
					  data: {
						  "key":key,
						  "projectId":projectId
					  },
					  success: function(data){
						  var resultJson = eval(data);
						  if(resultJson.code == '200'){
							  closeLoading();
							  alertx(resultJson.message);
						  }else{
							  closeLoading();
								alertx(resultJson.message);		  
						  }
						  $("#liImport").hide();
					  },
					  dataType: "json"
					});
			}
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a id="btn" href="${ctx}/pro/taskGroup/list?project.id=${e.project.id}">任务组列表</a></li>
		<shiro:hasPermission name="pro:taskGroup:create"><li><a href="javascript:void(0);" onclick="groupForm('','${e.project.id}');">任务组添加</a></li></shiro:hasPermission>
		<shiro:hasPermission name="pro:proLog:view">
			<li><a href="${ctx}/pro/proLog/list?project.id=${e.project.id}">项目日志</a>
			</li>
         </shiro:hasPermission>
         <li><a href="${ctx}/pro/project/ganttViewData?id=${e.project.id}">项目进度</a></li>
         <shiro:hasPermission name="pro:taskGroup:import">
			<li class="active"><a href="${ctx}/pro/taskGroup/previewList?project.id=${e.project.id}">任务导入</a>
			</li>
         </shiro:hasPermission>
	</ul>
	<form:form id="importForm" action="${ctx}/pro/taskGroup/preview" enctype="multipart/form-data" method="post" class="breadcrumb form-search">
		<input id="projectId" name="project.id" type="hidden" value="${e.project.id}"/>
		<input id="key" type="hidden" value="${preview.key}"/>
		<a href="${ctx}/pro/project/">项目&gt;&gt;</a>
		<ul class="ul-form">
			<li class="btns">
				<a class="btn btn-primary" href="${ctx}/pro/taskGroup/down">模板下载</a>
			</li>
			<li>
				<input type="file" name="file" id="myFile" class="input-medium"/>
			</li>
			<li id="fileSize"></li>
			<li class="btns">
				<input id="btnSubmit" class="btn btn-primary" type="submit" value="预览"/>
				<c:if test="${not empty preview.validList}">
					<li class="btns" id="liImport">
						<input id="btnImport" class="btn btn-primary" type="button" value="确认导入" onclick="importExcel();"/>
						<font color="red">*确认导入后将仅有合法数据能被成功导入</font>
					</li>
				</c:if>
			</li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<sys:message content="${message}"/>
	合法数据
	<table id="validTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>任务名称</th>
				<th>所属任务组</th>
				<th>负责人</th>
				<th>优先级</th>
				<th>开始时间</th>
				<th>结束时间</th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${preview.validList}" var="task">
			<tr>
				<td>
					${task.name}
				</td>
				<td>
					${task.groupName}
				</td>
				<td>
					${task.manager.name}
				</td>
				<td>
					${fns:getDictLabel(task.priority, 'task_priority', '')}
				</td>
				<td>
					<fmt:formatDate value="${task.startTime}" pattern="yyyy-MM-dd"/>
				</td>
				<td>
					<fmt:formatDate value="${task.endTime}" pattern="yyyy-MM-dd"/>
				</td>
				<%-- <td>
					<c:if test="${not empty task.endTime && task.delFlag=='0'}">
						<c:choose>
							<c:when test="${nowDate-task.endTime.time>0}">
								已超时
							</c:when>
							<c:otherwise>
								进行中
							</c:otherwise>
						</c:choose>
					</c:if>
					<c:if test="${task.delFlag == '1'}">
						已归档
					</c:if>
				</td> --%>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	非法数据
	<table id="failTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>任务名称</th>
				<th>所属任务组</th>
				<th>负责人</th>
				<th>优先级</th>
				<th>开始时间</th>
				<th>结束时间</th>
				<!-- <th>任务状态</th> -->
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${preview.failList}" var="task">
			<tr>
				<c:choose>
					<c:when test="${task.failReason == 2}">
						<td title="名称重复">
						<font color="red">${task.name}</font>
						</td>
					</c:when>
					<c:when test="${task.failReason == 3}">
						<td title="记录已存在">
						<font color="red">${task.name}</font>
						</td>
					</c:when>
					<c:otherwise><td>${task.name}</td></c:otherwise>
				</c:choose>
				<td>
					${task.groupName}
				</td>
				<td>
					<c:if test="${empty task.manager}">
						<font color="red">负责人不存在</font>
					</c:if>
					${task.manager.name}
				</td>
				<td>
					<c:if test="${empty task.priority}">
						<font color="red">优先级错误</font>
					</c:if>
					${fns:getDictLabel(task.priority, 'task_priority', '')}
				</td>
				<td>
					<fmt:formatDate value="${task.startTime}" pattern="yyyy-MM-dd"/>
				</td>
				<c:choose>
					<c:when test="${task.failReason == 1}">
						<td title="日期不合法">
						<font color="red"><fmt:formatDate value="${task.endTime}" pattern="yyyy-MM-dd"/></font>
						</td>
					</c:when>
					<c:otherwise>
						<td>
						<fmt:formatDate value="${task.endTime}" pattern="yyyy-MM-dd"/>
						</td>
					</c:otherwise>
				</c:choose>
				<%-- <td>
					<c:if test="${not empty task.endTime && task.delFlag=='0'}">
						<c:choose>
							<c:when test="${nowDate-task.endTime.time>0}">
								已超时
							</c:when>
							<c:otherwise>
								进行中
							</c:otherwise>
						</c:choose>
					</c:if>
					<c:if test="${task.delFlag == '1'}">
						已归档
					</c:if>
				</td> --%>
			</tr>
		</c:forEach>
		</tbody>
	</table>
</body>
</html>